﻿@using NetMongo.Entity
@model User

@{
    ViewBag.Title = "添加用户";
}
<h3>添加用户</h3>
<div class="col-lg-12">
    <form id="formUser" class="form-horizontal">
        <div class="form-group">
            <label class="col-sm-2 control-label" for="UserName"> 姓名：</label>
            <div class="col-sm-10">
                @Html.TextBoxFor(a => a.UserName, new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.UserName)
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <label class="col-sm-2 control-label" for="Sex"> 性别：</label>
            <div class="col-sm-10">
                @Html.TextBoxFor(a => a.Sex, new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.Sex)
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <label class="col-sm-2 control-label" for="Age"> 年龄：</label>
            <div class="col-sm-10">
                @Html.TextBoxFor(a => a.Age, new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.Age)
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <label class="col-sm-2 control-label" for="Interest"> 兴趣爱好：</label>
            <div class="col-sm-10">
                @Html.TextAreaFor(a => a.Interest, new { @class = "form-control", @style = "min-height:100px;min-width:600px;", @maxlength = "200" })
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <label class="col-sm-2 control-label no-margins" for="Remark">备注：</label>
            <div class="col-sm-10">
                @Html.TextAreaFor(a => a.Remark, new { @class = "form-control" , @style = "min-height:100px;min-width:600px;", @maxlength = "200" })
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-2">
                <button class="btn btn-primary" type="button" id="btnAdd">保存</button>
                <a class="btn btn-default" href="@Url.Action("Index","Home")">返回</a>
            </div>
        </div>
    </form>    
</div>
@section Scripts {
    <script>
        $(function () {
            //新增
            $("#btnAdd").click(function () {                
                $.post("@Url.Action("UserAdd","Home")", $("#formUser").serialize(), function (res) {
                    if (res.success) {
                        alert("新增成功");
                        window.location.href = "@Url.Action("Index","Home")";
                    }
                    else {
                        alert(res.msg);
                    }
                })
            });
        });
    </script>
}

